<!DOCTYPE html>
<html>
<head>
    <title>入库API详细调试</title>
    <style>
        body { font-family: Arial; margin: 20px; }
        .result { margin: 10px 0; padding: 10px; border: 1px solid #ccc; }
        .success { background: #d4edda; }
        .error { background: #f8d7da; }
        .info { background: #d1ecf1; }
        pre { white-space: pre-wrap; word-wrap: break-word; background: #f8f9fa; padding: 10px; border-radius: 4px; }
        button { padding: 10px 20px; margin: 10px; }
    </style>
</head>
<body>
    <h1>入库API详细调试</h1>
    
    <div class="info">
        <h3>测试说明</h3>
        <p>此页面用于详细调试入库API，检查分页参数和数据返回情况。</p>
    </div>

    <div>
        <label>页码: <input type="number" id="pageIndex" value="1" min="1"></label>
        <label>每页条数: <input type="number" id="pageSize" value="10" min="1" max="100"></label>
        <button onclick="testApi()">测试API</button>
    </div>

    <div id="result"></div>

    <script>
        async function testApi() {
            const resultDiv = document.getElementById('result');
            const pageIndex = document.getElementById('pageIndex').value;
            const pageSize = document.getElementById('pageSize').value;
            
            resultDiv.innerHTML = '<div class="info">测试中...</div>';
            
            try {
                console.log('开始测试入库API...');
                console.log('参数:', { pageIndex, pageSize });
                
                const url = `http://localhost:5000/api/Inbound/list?pageIndex=${pageIndex}&pageSize=${pageSize}`;
                console.log('请求URL:', url);
                
                const response = await fetch(url);
                console.log('响应状态:', response.status);
                
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                
                const data = await response.json();
                console.log('API响应数据:', data);
                
                if (data.code === 200) {
                    const pageData = data.data.pageData || [];
                    resultDiv.innerHTML = `
                        <div class="success">
                            <h3>✅ API调用成功</h3>
                            <p><strong>请求参数:</strong> pageIndex=${pageIndex}, pageSize=${pageSize}</p>
                            <p><strong>响应状态码:</strong> ${data.code}</p>
                            <p><strong>响应消息:</strong> ${data.message}</p>
                            <p><strong>总条数:</strong> ${data.data.totalCount}</p>
                            <p><strong>当前页:</strong> ${data.data.pageIndex}</p>
                            <p><strong>每页条数:</strong> ${data.data.pageSize}</p>
                            <p><strong>总页数:</strong> ${data.data.pageCount}</p>
                            <p><strong>当前页数据条数:</strong> ${pageData.length}</p>
                            
                            <h4>分页数据详情:</h4>
                            <pre>${JSON.stringify(pageData, null, 2)}</pre>
                            
                            <h4>完整响应:</h4>
                            <pre>${JSON.stringify(data, null, 2)}</pre>
                        </div>
                    `;
                } else {
                    resultDiv.innerHTML = `
                        <div class="error">
                            <h3>❌ API返回错误</h3>
                            <p><strong>状态码:</strong> ${data.code}</p>
                            <p><strong>消息:</strong> ${data.message}</p>
                            <pre>${JSON.stringify(data, null, 2)}</pre>
                        </div>
                    `;
                }
                
            } catch (error) {
                console.error('API测试失败:', error);
                resultDiv.innerHTML = `
                    <div class="error">
                        <h3>❌ API调用失败</h3>
                        <p><strong>错误:</strong> ${error.message}</p>
                        <p>请检查后端服务是否正在运行在 http://localhost:5000</p>
                    </div>
                `;
            }
        }

        // 页面加载时自动测试
        window.onload = function() {
            testApi();
        };
    </script>
</body>
</html> 